package com.viaas.certification.image.command;


import com.viaas.certification.image.action.AIModeManager;
import com.viaas.certification.image.action.AIPlayerMiner;
import com.viaas.certification.image.env.EnvironmentDetector;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.security.Provider;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

public class ChatCommand implements CommandExecutor {
    private final AIModeManager aiModeManager;
    Logger logger = Logger.getLogger("Minecraft");
    Map<String,AIPlayerMiner> cache = new HashMap<>();

    public ChatCommand(AIModeManager aiModeManager) {
        this.aiModeManager = aiModeManager;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "只有玩家可以使用这个指令！");
            return true;
        }
        Player player = (Player) sender;

        String action = args[0].toLowerCase();
        String keyword = args[1];
        AIPlayerMiner aiPlayerMiner = cache.get(player.getName());
        if(aiPlayerMiner == null){
            aiPlayerMiner = new AIPlayerMiner(player, Bukkit.getServer().getPluginManager().getPlugin("Monitor"));
            cache.put(player.getName(), aiPlayerMiner);
        }


        switch (action) {
            case "enable":
                aiPlayerMiner.startMining();
//                aiModeManager.enableAI(player);
                break;

            case "disable":
                aiPlayerMiner.stopMining();
//                aiModeManager.disableAI(player);
                break;

            default:
                sender.sendMessage(ChatColor.RED + "未知指令！");
                return false;
        }
        return true;
    }
}
